#pragma once

#include <string>
#include <windows.h>
#include "IProfileOutputHandler.h"

using namespace std;

#define MAX_PROFILER_SAMPLES 50

class EngineProfileSample
{
public:
	EngineProfileSample(string sampleName);
	~EngineProfileSample(void);

	static void Output();

	static void ResetSample(std::string sampleName);
	static void ResetAll();

	static IProfilerOutputHandler *outputHandler;
protected:
	//index into the array of samples
	int iSampleIndex;
	int iParentIndex;

	inline float GetTime(){ return GetTickCount()/1000.0f; }

	static struct profileSample
	{
		profileSample()
		{
			bIsValid=false; 
			dataCount=0;
			averagePc=minPc=maxPc=-1;
		}

		bool bIsValid;    //whether or not this sample is valid to be used
		bool bIsOpen;     //is this sample currently being profiled?
		unsigned int callCount; //number of times this sample has been executed, this frame
		string name; //name of the sample
    
		float startTime;  //starting time on the clock, in seconds
		float totalTime;  //total time recorded across all executions of this sample, this frame
		float childTime;  //total time taken by children of this sample, this frame

		int parentCount;  //number of parents this sample has (useful for neat indenting)

		float averagePc;  //average percentage of game loop time taken up
		float minPc;      //minimum percentage of game loop time taken up
		float maxPc;      //maximum percentage of game loop time taken up
		unsigned long dataCount; //number of times values have been stored since sample creation/reset
	} samples[MAX_PROFILER_SAMPLES];

	static int lastOpenedSample;
	static int openSampleCount;
	static float rootBegin, rootEnd;
};
